package org.example.database.service.impl;

import org.example.database.Mapper.RecruitmentPositionMapper;
import org.example.database.entity.RecruitmentPosition;
import org.example.database.service.RecruitmentPositionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 招聘职位管理服务实现类
 * 实现了对招聘职位信息的增删改查等业务逻辑
 */
@Service
public class RecruitmentPositionServiceImpl implements RecruitmentPositionService {

    @Autowired
    private RecruitmentPositionMapper recruitmentPositionMapper;

    /**
     * 添加新招聘职位
     * 将职位信息插入数据库，并自动生成职位编号
     *
     * @param position 职位实体对象
     * @return 插入成功返回1，失败返回0
     */
    @Override
    public int insert(RecruitmentPosition position) {
        return recruitmentPositionMapper.insert(position);
    }

    /**
     * 根据职位编号查询职位详情
     *
     * @param jobNumber 职位编号
     * @return 职位实体对象，如果不存在则返回null
     */
    @Override
    public RecruitmentPosition selectById(Integer jobNumber) {
        return recruitmentPositionMapper.selectById(jobNumber);
    }

    /**
     * 查询所有招聘职位
     *
     * @return 职位列表，若没有数据则返回空列表
     */
    @Override
    public List<RecruitmentPosition> selectAll() {
        return recruitmentPositionMapper.selectAll();
    }

    /**
     * 根据学历要求筛选职位
     *
     * @param educationalRequirement 学历要求，如"本科"、"硕士"等
     * @return 符合条件的职位列表，若无匹配则返回空列表
     */
    @Override
    public List<RecruitmentPosition> selectByEducationalRequirement(String educationalRequirement) {
        return recruitmentPositionMapper.selectByEducationalRequirement(educationalRequirement);
    }

    /**
     * 更新职位信息
     * 根据职位编号更新职位的各项信息
     *
     * @param position 包含更新信息的职位实体对象(必须包含jobNumber)
     * @return 更新成功返回1，失败返回0
     */
    @Override
    public int update(RecruitmentPosition position) {
        return recruitmentPositionMapper.update(position);
    }

    /**
     * 根据职位编号删除职位
     *
     * @param jobNumber 职位编号
     * @return 删除成功返回1，失败返回0
     */
    @Override
    public int deleteById(Integer jobNumber) {
        return recruitmentPositionMapper.deleteById(jobNumber);
    }
}